define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'pro/orderactivity/index',
                    // add_url: 'pro/orderactivity/add',
                    edit_url: 'pro/orderactivity/edit',
                    // del_url: 'pro/orderactivity/del',
                    // multi_url: 'pro/orderactivity/multi',
                    table: 'gzns_order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                queryParams: function (params) {
                    if (!params.filter) {
                        params.filter={}
                    }else {
                        params.filter = JSON.parse(params.filter)
                    }
                    if (!params.op) {
                        params.op={}
                    }else {
                        params.op = JSON.parse(params.op)

                    }
                    if (!params.filter.order_type && !params.op.order_type) {
                        params.filter.order_type = '2';
                        params.op.order_type = '='
                    }
                    // if (!params.filter.order_status && !params.op.order_status) {
                    //     params.filter.order_status = '1,2';
                    //     params.op.order_status = 'IN'
                    // }
                    params.filter = JSON.stringify(params.filter)
                    params.op = JSON.stringify(params.op)

                    return params;
                },
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'order_number', title: __('Order_number'),operate:'Like'},
                        {field: 'order_status', title: __('Order_status'), searchList: {"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3')}, formatter: Table.api.formatter.status},
                        // {field: 'user.company_name', title: __('User.vip.company_name'),operate:'Like'},
                        // {field: 'user.post', title: __('职务'),operate:'Like'},
                        // {field: 'user.nick_name', title: __('User.nick_name'),operate:'Like'},
                        // {field: 'user.real_name', title: __('User.real_name'),operate:'Like'},
                        // {field: 'user.phone', title: __('手机号'),operate:'Like'},
                        // {field: 'user.identity_code', title: __('User.identity_code'),operate:'Like'},
                        // {field: 'user_id', title: __('User_id')},
                        // {field: 'order_status', title: __('Order_status')},
                        // {field: 'pay_type', title: __('Pay_type')},
                        // {field: 'order_type', title: __('Order_type')},
                        {field: 'user_name', title: __('User_name')},
                        {field: 'user_phone', title: __('user_phone')},
                        {field: 'item.name', title: __('Item.name'),operate:'Like'},
                        {field: 'item.img', title: __('Item.img'), formatter: Table.api.formatter.image,operate:false},
                        // {field: 'item.price', title: __('Item.price'), operate:'BETWEEN'},
                        // {field: 'item.quantity', title: __('Item.quantity'), operate:'BETWEEN'},
                        // {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        // {field: 'actual_price', title: __('Actual_price'), operate:'BETWEEN'},
                        // {field: 'refused_price', title: __('Refused_price'), operate:'BETWEEN'},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'pay_time', title: __('Pay_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
          table.on('post-body.bs.table', function (e, settings, json, xhr) {
            $(".btn-editone,.btn-edit,.btn-add").data("area", ["100%", "100%"]);
          });
        },
        add: function () {
            Controller.api.bindevent();
        },
      edit: function () {
        Controller.api.bindevent();
        $('[data-status]').click(function () {
          var status = $(this).attr('data-status')
          $('#c-order_status').val(status)
          var tip = '确认吗'
          if(status == 2){
            tip = '确定设为已完成？'
          } else if(status == 3){
            tip = '确认取消订单？'
          }
          Layer.confirm(tip, {icon: 3, title:'提示'}, function(index){
            //do something
            $("form[role=form]").submit()
            Layer.close(index);
          });
          //
        })

      },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
